package com.ljx.qqpro.controller;

import java.util.Arrays;
import java.util.Map;

import cn.hutool.core.bean.BeanUtil;
import com.ljx.qqpro.common.utils.UserHolder;
import com.ljx.qqpro.dto.apply.ApplyDto;
import com.ljx.qqpro.vo.apply.ApplySave;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ljx.qqpro.entity.ApplyEntity;
import com.ljx.qqpro.service.ApplyService;
import com.ljx.qqpro.common.utils.PageUtil;
import com.ljx.qqpro.common.utils.Result;



/**
 * 申请表
 *
 * @author LiJunXi
 * @email 2770063826@qq.com
 * @date 2023-10-22 22:46:29
 */
@RestController
@RequestMapping("/apply")
public class ApplyController {
    @Autowired
    private ApplyService applyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtil page = applyService.queryPage(params);

        return Result.success(page, "page");
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		ApplyEntity apply = applyService.getById(id);

        return Result.success(apply, "apply");
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody ApplySave applySave){
        applyService.saveApply(applySave);

        return Result.success(null, "申请发送成功");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody ApplyEntity apply){
		applyService.updateById(apply);

        return Result.success(null, "");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		applyService.removeByIds(Arrays.asList(ids));

        return Result.success(null, "");
    }

    /**
     * 获取用户的通知（申请）
     * @return
     */
    @GetMapping("/getUserApply")
    public Result<ApplyDto> getUserApply(){
        Long userId = UserHolder.getUser().getId();
        ApplyDto applyDto = applyService.getUserApply(userId);

        return Result.success(applyDto, "获取用户通知成功");
    }

}
